home *** CD-ROM | disk | FTP | other *** search
- /* File: main.c
-
-
- The main program structure:
-
- int FixMenus()
- - Activate/Deactive menu as needed
-
- Edit Menu Stubs -- null routines...
-
- DoCommand(long mResult)
- - Handle all memu commands
-
- Boolean HandleEvents(EventRecord *myEvent);
-
- Initialize()
- - Setup up menus and Macintosh enviroment
-
- Main()
- - Setup QuickTime movie enviroment
- - Call Initialision routines
- - Call Main Event Handling routines
- - Cleanup QuickTime Movie Enviroment
-
- History..
- RMF Created from DTS from sample source code.
- Feb 9th,1994 RMF Add click in context for next preview image
- Fix up Menu structure (eg. Direction menu, Effect Menu).
- Added BackGround Color option on Slide
- */
-
- #include "gGlobals.h"
- #include <Picker.h>
- #include <pascal.h>
- #include <Scrap.h>
- #include <Desk.h>
- #include <string.h>
- #include <stdio.h>
- #include <Fonts.h>
- #include <Math.h>
-
- /* *****************************************************************************
-
- The following three routines are here because the MPW 3.2 c compiler
- screw up compiling the DoMovie routine if you use the "straight" calls.
-
- Try it and see and complain to DTS.
- */
-
- void DoHLock(Handle h)
- {
- HLock(h);
- }
- void DoHUnlock(Handle h)
- {
- HUnlock( h);
- }
-
- void DoDisposHandle(Handle h)
- {
- DisposHandle(h);
- }
-
- /*********************************************
-
- Clean up menu hiliting
-
- *********************************************/
-
- int FixMenus()
- {
- Boolean gotAllWindows;
- Boolean gotAnyWindows;
-
- gotAnyWindows = (gSrcWindow != nil || gAltWindow != nil);
- gotAllWindows = gSrcWindow != nil &&
- (!gRequiresAlternate || gAltWindow != nil );
- DisableItem(gMenus[FILE_MENU],FILE_M_SAVE);
- if ( gotAnyWindows )
- EnableItem(gMenus[FILE_MENU],FILE_M_CLOSE);
- else
- DisableItem(gMenus[FILE_MENU],FILE_M_CLOSE);
-
- if (gotAllWindows )
- DisableItem(gMenus[FILE_MENU],FILE_M_OPEN);
- else
- EnableItem(gMenus[FILE_MENU],FILE_M_OPEN);
-
- if ( !gotAllWindows ) {
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_APPEND);
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_MOVIE);
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_PREVIEW);
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_OVERSAMPLE);
- } else {
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_APPEND);
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_MOVIE);
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_PREVIEW);
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_OVERSAMPLE);
- }
-
- DisableItem(gMenus[EDIT_MENU],EDIT_M_CUT);
- DisableItem(gMenus[EDIT_MENU],EDIT_M_COPY);
- DisableItem(gMenus[EDIT_MENU],EDIT_M_PASTE);
-
- DisableItem(gMenus[EDIT_MENU],EDIT_M_CLEAR);
- DisableItem(gMenus[EDIT_MENU],EDIT_M_UNDO);
- CheckItem(gMenus[MOVIE_MENU],MOVIE_M_OVERSAMPLE,gOversample);
-
- CheckItem(gMenus[Direction_Menu],EFFECT_BACKWARDS,gReverse);
- CheckItem(gMenus[Direction_Menu],gEffectDirection,true);
- CheckItem(gMenus[EFFECT_MENU],gEffectType,true);
-
- }
-
- Boolean OptionDown(void)
- { KeyMap k;
- GetKeys(&k);
- return (BitTst(&k, 61)); /* true if option is down */
- } /* End of OptionDown() */
-
- Boolean ShiftDown(void)
- { KeyMap k;
- GetKeys(&k);
- return (BitTst(&k, 48)); /* true if shift is down */
- } /* End of ShiftDown() */
-
- /*********************************************
-
- Stubs
-
- ********************************************/
-
- OSErr DoCopy()
- {
-
- }
-
- OSErr DoCut()
- {
- }
-
-
- OSErr DoPaste()
- {
-
- }
-
- void DoClear()
- {
-
-
- }
-
- OSErr DoUndo()
- {
-
-
- }
-
-
- /*********************************************
-
- Process menu command.
-
- ********************************************/
-
- DoCommand(long mResult)
- {
- short theMenu, theItem;
- Str255 daName;
- GDHandle saveGD;
- CGrafPtr savePort;
- OSErr res = 0;
-
- #define HIshort(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LOshort(aLong) ((aLong) & 0xFFFF)
-
- theItem = LOshort(mResult);
- theMenu = HIshort(mResult); /* This is the resource ID */
-
-
- switch (theMenu) {
- case APPLE_MENU_ID:
- if (theItem == 1) {
- ShowAboutBox();
- } else {
- GetItem(gMenus[0], theItem, daName);
- GetGWorld(&savePort,&saveGD);
- (void) OpenDeskAcc(daName);
- SetGWorld(savePort,saveGD);
- }
- break;
-
- case FILE_MENU_ID:
- { switch (theItem) {
- case FILE_M_OPEN: DoOpen(nil); FixMenus(); break;
- case FILE_M_CLOSE: DoClose(gActiveWindow); FixMenus(); res = 1;
- break;
- case FILE_M_SAVE: break;
-
- case fileImport: importMovie(); break;
- case fileExport: exportMovie(); break;
-
-
- case FILE_M_QUIT:
- { Boolean abortion = false;
- while ( gActiveWindow ) {
- if ( DoClose(gActiveWindow) < 0 ) {
- abortion = true; break;
- }
- }
- if ( !abortion ) gExitFlag = true; /* Request exit */
- res = 1;
- break;
- }
- }
- }
- break;
-
- /******************************/
-
- case EDIT_MENU_ID:
- if ( !SystemEdit(theItem-1) ) {
- switch ( theItem ) {
- case EDIT_M_UNDO: DoUndo(); break;
- case EDIT_M_CUT: DoCut(); break;
- case EDIT_M_COPY: DoCopy(); break;
- case EDIT_M_PASTE: DoPaste(); break;
- case EDIT_M_CLEAR: DoClear(); break;
- }
- }
- break;
-
- /******************************/
- case Direction_MenuID:
-
- if (EFFECT_BACKWARDS == theItem) {
- gReverse = !gReverse;
- } else {
- CheckItem(gMenus[Direction_Menu],gEffectDirection,false);
- gEffectDirection = theItem;
- }
- break;
-
- case EFFECT_MENU_ID:
- switch (theItem) {
- case EFFECT_CrossFad:
- gStandardP.depth = 32; // randomdotstereogram needs 8bit grayscale buffers (40), 32 = RGBa color
- gRequiresAlternate = true; // needs two picts to do processing
- break;
- case EFFECT_Slide:
- gStandardP.depth = 32; // randomdotstereogram needs 8bit grayscale buffers (40), 32 = RGBa color
- gRequiresAlternate = false; // only needs one pict to do processing
- break;
- case EFFECT_Roll:
- gStandardP.depth = 32; // randomdotstereogram needs 8bit grayscale buffers (40), 32 = RGBa color
- gRequiresAlternate = false; // only needs one pict to do processing
- break;
-
- case EFFECT_StereoGram:
- gStandardP.depth = 40; // randomdotstereogram needs 8bit grayscale buffers (40), 32 = RGBa color
- gRequiresAlternate = false; // only needs one pict to do processing
- break;
-
- case EFFECT_BACKColor:
- { Point where;
- RGBColor outColor;
- SetPt(&where, 32, 32);
- if (GetColor(where,"\pSelect Color", &BACKColor, &outColor)) {
- BACKColor = outColor;
- }
- }
- } /* End switch */
-
- if (EFFECT_BACKColor != theItem) {
- CheckItem(gMenus[EFFECT_MENU],gEffectType,false);
- gEffectType = theItem;
-
- gStandardP.flags = scShowMotionSettings;
- gStandardP.theCodecType = kCodecType;
- gStandardP.theCodec = kCodecID;
- gStandardP.spatialQuality = kCodecQuality;
- gStandardP.temporalQuality = 0;
- gStandardP.depth = kCodecDepth;
- gStandardP.frameRate = kFrameRate<<16;
- gStandardP.keyFrameRate = kFrameRate;
- }
- break;
-
- /******************************/
-
- case MOVIE_MENU_ID:
- switch ( theItem ) {
- case MOVIE_M_COMPRESS : SetCompression();
- break;
-
- case MOVIE_M_STAGES : SetStages();
- break;
-
- case MOVIE_M_OVERSAMPLE: gOversample = !gOversample;
- break;
-
- case MOVIE_M_PREVIEW : DoPreview(true);
- break;
-
- case MOVIE_M_MOVIE : DoMovie(false);
- break;
-
- case MOVIE_M_APPEND : DoMovie(true);
- break;
- }
- break;
- }/*endsw theMenu*/
-
- HiliteMenu(0);
- return(res);
- } /* End of () */
-
-
- /********************************************
-
- Process events.
-
- ********************************************/
-
- Boolean HandleEvents(EventRecord *myEvent)
- { Rect dragRect;
- WindowPtr whichWindow;
- short res = 0;
- GWorldPtr saveWorld;
- GDHandle saveGD;
-
- GetGWorld(&saveWorld,&saveGD);
-
- switch (myEvent->what) {
- case mouseDown:
-
- switch ((short)FindWindow(myEvent->where, &whichWindow)) {
- case inSysWindow: SystemClick(myEvent, whichWindow);
- break;
-
- case inMenuBar:
- FixMenus();
- res = DoCommand(MenuSelect(myEvent->where));
- break;
-
- case inDrag:
- SetPort((GrafPtr)whichWindow);
- SetRect(&dragRect, 4, 20 + 4, qd.screenBits.bounds.right-4, qd.screenBits.bounds.bottom-4);
- DragWindow(whichWindow, myEvent->where, &dragRect);
- break;
-
- case inGrow: break;
- case inZoomIn: break;
- case inZoomOut: break;
-
- case inGoAway:
- if ( TrackGoAway(whichWindow,myEvent->where) ) {
- DoClose(whichWindow); res = true;
- }
- break;
-
-
- case inContent:
- if ( whichWindow != FrontWindow() ) {
- SelectWindow(whichWindow); gActiveWindow = whichWindow;
- } else {
- if (whichWindow && whichWindow == (WindowPtr) gDstWindow ) DoPreview(false);
- }
- break;
- } /* End Switch() */
- break;
-
- case keyDown:
- if ( ((myEvent->modifiers & cmdKey) != 0) ) {
- res = DoCommand(MenuKey(myEvent->message & charCodeMask));
- } else {
-
- }
- break;
-
- case updateEvt: DoUpdate((CWindowPtr)myEvent->message);
- break;
-
- case activateEvt:
- whichWindow=(WindowPtr)myEvent->message;
- if ( (myEvent->modifiers & activeFlag) ) {
- gActiveWindow = whichWindow;
- }
- break;
- } /* End Switch() */
-
- SetGWorld(saveWorld,saveGD);
- return(res);
- } /* End of () */
-
-
- /*********************************************
-
- Initialize menu bar.
-
- *********************************************/
-
- SetupMenus()
- {
- gMenus[APPLE_MENU] = GetMenu(APPLE_MENU_ID);
- AddResMenu(gMenus[APPLE_MENU], (ResType) 'DRVR');
- InsertMenu(gMenus[APPLE_MENU], 0);
- gMenus[FILE_MENU] = GetMenu(FILE_MENU_ID);
- InsertMenu(gMenus[FILE_MENU], 0);
- gMenus[EDIT_MENU] = GetMenu(EDIT_MENU_ID);
- InsertMenu(gMenus[EDIT_MENU], 0);
- gMenus[MOVIE_MENU] = GetMenu(MOVIE_MENU_ID);
- InsertMenu(gMenus[MOVIE_MENU], 0);
- gMenus[EFFECT_MENU] = GetMenu(EFFECT_MENU_ID);
- InsertMenu(gMenus[EFFECT_MENU], 0);
- gMenus[Direction_Menu] = GetMenu(Direction_MenuID);
- InsertMenu(gMenus[Direction_Menu], -1);
- DrawMenuBar();
-
- } /* End of () */
-
- /*********************************************
-
- Prepare for work.
-
- *********************************************/
-
- int Initialize()
- { OSErr err;
- Ptr size;
- long resp;
-
- size = GetApplLimit();
- SetApplLimit(size - 32*1024); /* make room on stack so Quickdraw can do big pictures */
- MaxApplZone();
-
- /* initialize managers */
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitDialogs(nil);
- InitCursor();
- FlushEvents(everyEvent, 0);
-
- SetupMenus(); /* Check off correct memus and hilight them */
-
- CouldAlert(140); /* Load Alert into Memory ... incase of out of memory errors */
-
-
- if ( NGetTrapAddress(0xab1d,ToolTrap) == NGetTrapAddress(0x9f,ToolTrap) ) {
- return -1;
- }
- if ( Gestalt(gestaltQuickTime, &resp) != 0 ) {
- return -1;
- }
-
- gHasNewStdFile = false; /* Check for preview and new standard file stuff */
- err = Gestalt(gestaltStandardFileAttr,&resp);
- if ((err == 0) && ((resp & (0x00000001 << gestaltStandardFile58)) != 0))
- gHasNewStdFile = true;
-
- InitSetCompression(); /* Setup default QT compression settings */
-
- return 0;
- } /* End of () */
-
-
- /*********************************************
-
- If some kind of fatal error happened come here.
-
- *********************************************/
-
- void Error(char *msg, OSErr code)
- { Str15 buf;
- GWorldPtr saveWorld;
- GDHandle saveGD;
- CGrafPtr wmgrPort;
- extern char *moviesErrorNames[];
-
- GetGWorld(&saveWorld,&saveGD); GetCWMgrPort(&wmgrPort);
- SetGWorld(wmgrPort,nil);
- if (code ) {
- NumToString(code, buf);
- } else buf[0] = 0;
-
- c2pstr(msg);
- if (code >= -2051 && code<= -2000) {
- c2pstr(moviesErrorNames[-code - 2000]);
- ParamText((StringPtr)msg,buf,(StringPtr) moviesErrorNames[-code - 2000],0);
- p2cstr((StringPtr)moviesErrorNames[-code - 2000]);
- } else
- ParamText((StringPtr)msg,buf,0,0);
- if ( code == 0 )
- Alert(140,nil);
- else
- StopAlert(140,nil);
- p2cstr((StringPtr) msg);
-
- SetGWorld(saveWorld,saveGD);
- } /* End of () */
-
-
- ShowAboutBox()
- {
-
- ParamText( "\pCreated from:\r\rPictMovier & ImportExportMovie QuickTime Sample Code",
- "\p",
- "\p\r\rChange By R.Mark Fleming <MarkF@post.QueensU.CA",0);
- Alert(140,nil);
- } /* End of () */
-
-
- /********************************************
-
- The main program
-
- - Setup QuickTime movie enviroment
- - Call Initialision routines
- - Call Main Event Handling routines
- - Cleanup QuickTime Movie Enviroment
-
- ********************************************/
-
- main()
- { EventRecord myEvent;
-
- if (Initialize()) {
- SysBeep(0); ExitToShell();
- }
-
- EnterMovies();
-
- gStandardP.theCodecType = 'smc '; // graphics compressor is good choice
- if ( gEffectType == EFFECT_StereoGram) {
- gStandardP.depth = 40; // randomdotstereogram needs grayscale buffers
- } else {
- gStandardP.depth = 32; // full resolution for best effect
- }
- gRequiresAlternate =
- (EFFECT_CrossFad == gEffectType) ? true : false ; // needs two picts to do processing
-
- while ( !gExitFlag ) {
- if ( WaitNextEvent( everyEvent, &myEvent, 1, nil) != 0 ) {
- HandleEvents(&myEvent);
- }
- }
-
- done:
- ExitMovies();
- ExitToShell();
- } /* End of () */
-